<?php


namespace app\controller;


use app\model\inboundModel;
use think\facade\Request;

class inbound
{
private $model;

    public function __construct()
    {
        $this->model = new inboundModel();
}
    public function getList()
    {
        $param=Request::get();
        $map = [];
        if (isset($param['name'])&& $name = trim($param['name'])) {
            $map[] = ["name", 'like', "%" . $name . "%"];
        }
        if (isset($param['type_id'])&&$param['type_id']){
            $map[] = ['type_id', '=', $param['type_id']];
        }
        $data=$this->model->with(['inboundType','bigCate','smallCate'])->where($map)->paginate([
            'query' => $param,
            'var_page' => 'current_page',
            'list_rows' => $param['pagesize'],
        ])->toArray();
        file_put_contents('1.txt', var_export(111, 1));
        if ($data) $meta=['status'=>200];
        else $meta=['status'=>400];
        return json(['data'=>$data,'meta'=>$meta]);
    }

    public function add()
    {
        $data = Request::post();
        $data['in_sn'] = date("YmdHis", time());
        $this->model->addData($data);
        return json(['meta'=>['msg'=>'新增成功','status'=>200]]);
    }
}